import {request} from '../../request/request';
let app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        switch_id:"",
        userid:"",
        otherUserId:"",
        result:{}
    },
    setid(e){
        this.setData({switch_id:e.detail.switch_index});
    },
    backfun(e){
        let oid = e.detail.params.userid;
        let uid = this.data.userid;
        request({url:app.data.url+"socket/agree",data:{uid,oid}}).then(res=>{
            wx.showToast({
              title: '已同意好友申请',
              icon:"success"
            })
            this.initData();
        })
    },
    disagreeFun(e){
        let {oid} = e.target.dataset;
        let uid = this.data.userid;
        request({url:app.data.url+"socket/disagree",data:{uid,oid}}).then(res=>{
            wx.showToast({
              title: '已拒绝好友申请',
              icon:"none"
            })
            this.initData();
        })
        
    },
    initData(){
        let this_ = this;
        wx.getStorage({
          key: 'userState',
          success:res=>{
              request({url:app.data.url+"users/getUser",data:{code:res.data}}).then(result=>{
                this_.setData({userid:result.data.message[0].id});
                return new Promise((resolve,reject)=>{
                    resolve(result.data.message[0].id)
                })
              }).then(uid=>{
                  request({url:app.data.url+"socket/useritems",data:{userid:uid}}).then(result=>{
                    //   console.log(result);
                    this_.setData({result:result.data.message});
                  })
              })
          }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({switch_id:options.switch_index});
        this.initData();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        app.setTheme(app.data.themeid)
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})